﻿/**
 * @author Anix
 */
import com.xvm.Logger;
import com.xvm.Utils;

/**
 * EquipmentLoader from config file
 * 
 */

class wot.hangar.AmmunitionPanel.DeviceSlot extends net.wargaming.hangar.AmmunitionPanel.DeviceSlot

{
	//var select, icon, locked, selectedId, _name, _parent, _target;

    function DeviceSlot()
    {
		Utils.TraceXvmModule("hangar_DeviceSlot");
        super();
    } // End of the function
    function configUI()
    {
		
        Mouse.addListener(this);
        select.addEventListener("rollOver", this, "onOver");
        select.addEventListener("rollOut", this, "onOut");
        select.addEventListener("press", this, "onOut");
        select.addEventListener("change", this, "onChange");
        select.addEventListener("itemClick", this, "onChange");
        select.addEventListener("select", this, "highlightParams");
        select.changeFocus = function ()
        {
            super.changeFocus();
        };
    } // End of the function
    function setSlotIndex(slotIdx)
    {
        this.slotIdx = slotIdx;
    } // End of the function
    function setSlotType(type)
    {
        slotType = type;
    } // End of the function
    function setIcon(iconSource, removable)
    {
        if (iconSource != "")
        {
            icon.__set__visible(true);
            icon.__set__source(iconSource);
            locked._visible = !removable;
        }
        else
        {
            icon._visible = true;
            icon.__set__source("../maps/icons/artefact/empty.png");
            locked._visible = false;
        } // end else if
    } // End of the function
	
	// Навели мышь
    function onOver(event)
    {
        if (selectedIndex > -1)
        {
            var _loc2 = dataValues[selectedIndex];
            var _loc3 = [0, 0];
            _loc3[_loc2.currency == "credits" ? (0) : (1)] = _loc2.price;
			
			//***********
			//Logger.addObject(_loc2.id, "ToolTip_ID");
			//Logger.add("ToolTip_invCount=" + _loc2.inventoryCount + " ToolTip_vehicleCount=" + _loc2.vehicleCount + " ToolTip_slotIdx=" + _loc2.slotIdx)
			            
			net.wargaming.managers.ToolTipManager.__get__instance().showHangarModule(_loc2.id, _loc3, _loc2.inventoryCount, _loc2.vehicleCount, _loc2.slotIdx);
        }
        else
        {
            net.wargaming.managers.ToolTipManager.__get__instance().showComplex("#tooltips:hangar/ammo_panel/device/empty");
        } // end else if
        return (true);
    } // End of the function
	
	// Убрали мышь
    function onOut(event)
    {
        net.wargaming.managers.ToolTipManager.__get__instance().hide();
        return (true);
    } // End of the function
	
	// Список доп оборудования из выпадающих списков слотов
    function setValues(values, price1, status1, price2, status2)
    {
        selectedIndex = -1;
        dataValues = new Array();
        for (var _loc2 = 0; _loc2 < values.length; _loc2 = _loc2 + 18)
        {
            var _loc12 = values[_loc2 + 0];
            var _loc8 = values[_loc2 + 1];
            var _loc16 = values[_loc2 + 2];
            var _loc14 = values[_loc2 + 3];
            var _loc13 = values[_loc2 + 4];
            var _loc11 = values[_loc2 + 5];
            var _loc22 = values[_loc2 + 6];
            var _loc6 = values[_loc2 + 7 + slotIdx * 3 + 0];
            var _loc10 = values[_loc2 + 7 + slotIdx * 3 + 1];
            var _loc9 = values[_loc2 + 7 + slotIdx * 3 + 2];
            var _loc4 = values[_loc2 + 16];
            var _loc7 = values[_loc2 + 17];
            var _loc5 = _loc14 == 1 && slotIdx == _loc4;
            var _loc18 = _loc14 == 1 && slotIdx != _loc4 ? ("#menu:moduleFits/wrong_slot") : (_loc6);
            dataValues[dataValues.length] = {id: _loc12, name: _loc8, desc: _loc16, target: _loc14, price: _loc13, currency: _loc11, icon: _loc22, status: _loc18, removable: _loc7, slotIdx: _loc4, isSelected: _loc5, inventoryCount: _loc10, vehicleCount: _loc9, removeCredits: {price: price2, status: status2}, removeGold: {price: price2, status: status2}};
            if (_loc5)
            {
                selectedIndex = dataValues.length - 1;
            } // end if
        } // end of for
		
        var _loc24 = select.__get__disabled();
        select.__set__disabled(true);
        select.__set__dataProvider(dataValues);
        this.update(Stage.width, Stage.height);
        select.__set__selectedIndex(selectedIndex);
        if (selectedIndex >= 0)
        {
            this.setIcon(dataValues[selectedIndex].icon, dataValues[selectedIndex].removable);
        }
        else
        {
            this.setIcon("", true);
        } // end else if
        select.__set__disabled(_loc24);
		
		//++++++++++++++++++
		//Logger.add("select.__set__selectedIndex=" + select.__set__selectedIndex);
		//Logger.addObject(select, "DeviceSlot select", 3);	
		//Logger.addObject(select.selectedItem, "DeviceSlot select.selectedItem");
		//Logger.addObject(select._label, "DeviceSlot select._label", 3);
		//Logger.addObject(select._dataProvider, "DeviceSlot select._dataProvider", 3);
		
		//Logger.addObject(dataValues[selectedIndex].id, "dataValues.id");	
		//Logger.add("selectedIndex=" + selectedIndex  + " name=" + dataValues[selectedIndex].name + " slotIdx=" + dataValues[selectedIndex].slotIdx);
		//Logger.addObject(dataValues[selectedIndex].id, "dataValues.id");	
		
    } // End of the function
    function update(w, h)
    {
        var _loc2 = Math.round((h - 300) / 58);
        select.__set__rowCount(Math.min(_loc2, select.__get__dataProvider().length));
        select.__set__scrollBar(select.__get__dataProvider().length <= _loc2 ? (null) : ("ScrollBar"));
    } // End of the function
	
    function onChange(event)
    {
		//*****
		//Logger.addObject(event, "OnChange_event")
        //Logger.add("OnChange: selectindex= " + selectedIndex)
		//Logger.add("OnChange: select.__get__selectedIndex=" + select.__get__selectedIndex())
		//*****
		
		if (select.__get__disabled() != true && selectedIndex != select.__get__selectedIndex())
        {
            if (selectedIndex != -1 && !dataValues[selectedIndex].removable)
            {
                var _loc2 = new Object();
                _loc2.src = "destroy_artefact.swf";
                _loc2.type = "dismantle";
                _loc2.text = "#dialogs:removeConfirmationNotRemovableGold/messageCombine";
                _loc2.name = dataValues[selectedIndex].name;
                _loc2.currency = "gold";
                _loc2.price = dataValues[select.__get__selectedIndex()].removeGold.price;
                 var _loc4 = net.wargaming.Account.addGoldCallBack(this, null);
                _loc2.priceStatus = Number(_loc4) >= Number(dataValues[select.__get__selectedIndex()].removeGold.price) ? (true) : (false);
                _loc2.priceInfo = "#dialogs:removeConfirmationNotRemovableGold/messagePrice";
                _loc2.useListenerPayStat = true;
                var _loc3 = net.wargaming.dialogs.DynamicContentDialog.show("removeConfirmationNotRemovableGold", true, true, true, _loc2);
                _loc3.contentOffsetLeft = -10;
                _loc3.contentOffsetTop = -10;
                _loc3.minHeight = 176;
                _loc3.submitDisabled = !_loc2.priceStatus;
                _loc3.addEventListener("submit", this, "onRemoveConfirmGold");
                _loc3.addEventListener("close", this, "onCancel");
            }
            else if (!dataValues[select.__get__selectedIndex()].removable)
            {
                var _loc3 = net.wargaming.notification.MessageDialog.show("installConfirmationNotRemovable", true);
                _loc3.message = net.wargaming.managers.Localization.makeString("#dialogs:installConfirmationNotRemovable/messageCombine", {name: dataValues[select.__get__selectedIndex()].name});
                _loc3.addEventListener("submit", this, "onRemoveConfirm");
                _loc3.addEventListener("close", this, "onCancel");
            }
            else
            {
                this.onRemoveConfirm(event);
            } // end else if
        } // end else if
    } // End of the function
	
    function onRemoveConfirm(e)
    {
        selectedId = dataValues[select.__get__selectedIndex()].id;
		gfx.io.GameDelegate.call("hangar.FittingChange", [selectedId, slotIdx, false]);
	} // End of the function
	
    function onRemoveConfirmGold(e)
    {
        selectedId = dataValues[select.__get__selectedIndex()].id;
        var _loc2 = true;
        gfx.io.GameDelegate.call("hangar.FittingChange", [selectedId, slotIdx, _loc2]);
    } // End of the function
    function onCancel(e)
    {
        select.__set__disabled(true);
        select.__set__selectedIndex(selectedIndex);
        select.__set__disabled(false);
    } // End of the function
    function highlightParams(e)
    {
        if (e.target.isOpen)
        {
            _parent._parent.params.highlightParams(_name);
        }
        else
        {
            _parent._parent.params.highlightParams("Empty");
        } // end else if
    } // End of the function
    function onMouseDown(button, target)
    {
        if (Mouse.RIGHT == button && target.indexOf("popup") < 0)
        {
            var _loc5 = "";
            var _loc4 = _target.split("");
            for (var _loc3 = 0; _loc3 < _loc4.length; ++_loc3)
            {
                _loc5 = _loc5 + (_loc4[_loc3] == "/" ? (".") : (_loc4[_loc3]));
            } // end of for
            if (target.indexOf(_loc5) > 0 && select.__get__selectedIndex() > -1)
            {
                _root.showInfoWnd(dataValues[select.__get__selectedIndex()].id, true);
                select.close();
            } // end if
        } // end if
    } // End of the function
} // End of Class
